package com.glsc.ngateway.common.base.domain.mysql.gateway.platform;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.glsc.ngateway.common.base.domain.mysql.BaseEntity;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.time.LocalDateTime;

/**
 * @author xuchang
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Where(clause = "deleted = 0")
@SQLDelete(sql = "update t_gw_owncloud_system_dir_config set deleted = UNIX_TIMESTAMP(NOW()), handled = 0 where id=?")
@SQLDeleteAll(sql = "update t_gw_owncloud_system_dir_config set deleted = UNIX_TIMESTAMP(NOW()), handled = 0 where id=?")
@Table(name = "t_gw_owncloud_system_dir_config")
public class OwnCloudSystemDirConfig extends BaseEntity {

    private static final long serialVersionUID = 3658913032559170208L;

    @Column(name = "parent_id", columnDefinition = "varchar(256) comment '父目录id'")
    private Long parentId;

    @Column(name = "name", columnDefinition = "varchar(256) comment '目录名称'")
    private String name;

    @Column(name = "parent_name", columnDefinition = "varchar(256) comment '父目录名称'")
    private String parentName;

    @Column(name = "parent_path", columnDefinition = "varchar(1024) comment '父目录路径'")
    private String parentPath;

    @Column(name = "path", columnDefinition = "varchar(1024) comment '目录路径'")
    private String path;

    @Builder.Default
    @Column(name = "valid", columnDefinition = "tinyint DEFAULT 0 comment '是否生效'")
    private boolean valid = false;

    @Column(name = "version_time", columnDefinition = "datetime comment '版本时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime versionTime;

}
